package guis;

import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.KeyStroke;

public class ComponentFactory
{
	public static JCheckBox createJCheckBox( int x, int y, Container content )
	{
		JCheckBox ret;

		ret = new JCheckBox();
		ret.setLocation( x, y );
		ret.setSize( 110, 35 );
		content.add( ret );

		return ret;
	}
	
	public static JButton createJButton( String title, int x, int y, Container content )
	{
		JButton ret;

		ret = new JButton( title );
		ret.setLocation( x, y );
		ret.setSize( 110, 35 );
		content.add( ret );

		return ret;
	}

	public static JButton createJButton( String title, boolean enabled, int width, int height, int x, int y, ImageIcon icon, Container content )
	{
		JButton ret;

		ret = new JButton( title, icon );
		ret.setLocation( x, y );
		ret.setSize( width, height );
		ret.setHorizontalTextPosition( AbstractButton.CENTER );
		ret.setVerticalTextPosition( AbstractButton.BOTTOM );
		ret.setEnabled( enabled );
		content.add( ret );

		return ret;
	}
	
	public static JRadioButton createJRadioButton( String title, int x, int y, ButtonGroup group, Container content )
	{
		JRadioButton ret;
		
		ret = new JRadioButton( title );
		ret.setLocation( x, y );
		ret.setSize( 110, 35 );
		group.add( ret );
		content.add( ret );
		
		return ret;
	}

	public static JPanel createJPanel( String title, int width, int height, int x, int y, Container content )
	{
		JPanel ret;

		ret = new JPanel( null );
		ret.setSize( width, height );
		ret.setLocation( x, y );
		ret.setBorder( BorderFactory.createTitledBorder( title ) );
		ret.setVisible( false );
		ret.setBackground( content.getBackground() );
		content.add( ret );

		return ret;
	}

	public static JPanel createJPanel( int width, int height, int x, int y, Container content )
	{
		JPanel ret;

		ret = new JPanel( null );
		ret.setSize( width, height );
		ret.setLocation( x, y );
		ret.setVisible( false );
		ret.setBackground( content.getBackground() );
		content.add( ret );

		return ret;
	}

	public static JTextField createJTextField( int width, int height, int x, int y, Container content )
	{
		JTextField ret;

		ret = new JTextField();
		ret.setBounds( x, y, width, height );
		content.add( ret );

		return ret;
	}
	
	public static JComboBox createJComboBox( Vector< ? > objects, int width, int height, int x, int y, Container content )
	{
		JComboBox ret;
		
		if( objects == null ) ret = new JComboBox();
		else ret = new JComboBox( objects );
		ret.setBounds( x, y, width, height );
		ret.setMaximumRowCount( 15 );
		content.add( ret );
		
		return ret;
	}
	
	public static JComboBox createJComboBox( Object[] objects, int width, int height, int x, int y, Container content )
	{
		JComboBox ret;
		
		if( objects == null ) ret = new JComboBox();
		else ret = new JComboBox( objects );
		ret.setBounds( x, y, width, height );
		ret.setMaximumRowCount( 15 );
		content.add( ret );
		
		return ret;
	}

	public static void createLabel( String titulo, int x, int y, Container content )
	{
		JLabel ret;

		ret = new JLabel( titulo );
		ret.setSize( 160, 20 );
		ret.setLocation( x, y );
		Font f = ret.getFont();
		ret.setFont( new Font( f.getName(), Font.BOLD, f.getSize() ) );

		content.add( ret );
	}

	public static JMenuBar createJMenuBar( JFrame content )
	{
		JMenuBar ret;

		ret = new JMenuBar();
		content.setJMenuBar( ret );

		return ret;
	}

	public static JMenu createJMenu( String title, JMenuBar content )
	{
		JMenu ret;

		ret = new JMenu( title );
		content.add( ret );

		return ret;
	}

	public static JMenu createJMenu( String title, JMenu content )
	{
		JMenu ret;

		ret = new JMenu( title );
		content.add( ret );

		return ret;
	}

	public static JMenuItem createJMenuItem( String title, ActionListener action, JMenu content )
	{
		JMenuItem ret;

		ret = new JMenuItem( title );
		ret.addActionListener( action );
		content.add( ret );

		return ret;
	}

	public static JMenuItem createJMenuItem( String title, ActionListener action, int mneumonic, JMenu content )
	{
		JMenuItem ret;

		ret = new JMenuItem( title + "     " );
		ret.addActionListener( action );
		ret.setAccelerator( KeyStroke.getKeyStroke( mneumonic, ActionEvent.ALT_MASK ) );
		content.add( ret );

		return ret;
	}
}
